package com.Leetcode;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

public class Index884uncommonFromsSentences {
	public static void main(String[] args) {
		String s1 = "apple apple", s2 = "apple";
		Index884uncommonFromsSentences uncommon = new Index884uncommonFromsSentences();
		String[] str = uncommon.uncommonFromSentences(s1, s2);
		for(String s : str)
			System.out.println(s);
	}
	
	public String[] uncommonFromSentences(String s1, String s2) {
        Map<String,Integer> uncon = new HashMap<>();
        String ans = "";
        String[] word = (s1+" "+s2).split(" ");
        for(int i = 0; i < word.length; i++)
            uncon.put(word[i],uncon.getOrDefault(word[i],0)+1);
        for (Entry<String, Integer> entry : uncon.entrySet()) {
               if(entry.getValue() == 1)
                    ans+=entry.getKey()+",";
            }
        return ans.equals("") ? new String[0]: ans.substring(0,ans.length()-1).split(",");
    }
}
